﻿using BankTransfer.Bank.Domain.Extarnal;
using BankTransfer.Bank.Infrastructure.Extarnal.Service;
using BankTransfer.Bank.Types.Enum;
using BankTransfer.Bank.Types.Types;

namespace BankTransfer.Bank.Infrastructure.Extarnal.Impl
{
    public class ExchangeRateServiceImpl : IExchangeRateService
    {
        private readonly YahooForexService yahooForexService;

        public ExchangeRateServiceImpl(YahooForexService yahooForexService)
        {
            this.yahooForexService = yahooForexService;
        }

        public ExchangeRate GetExchangeRate(Currency source, Currency target)
        {
            if (source.Equals(target))
            {
                return new ExchangeRate(1, source, target);
            }
            decimal forex = yahooForexService.GetExchangeRate(source.ToString(), target.ToString());
            return new ExchangeRate(forex, source, target);
        }
    }
}